package com.probiz.estore.system.service.impl;

import java.util.List;

import org.apache.commons.lang.RandomStringUtils;

import com.probiz.estore.common.model.system.AppAdmin;
import com.probiz.estore.common.util.DateUtil;
import com.probiz.estore.core.search.SearchCriteria;
import com.probiz.estore.system.dao.AppAdminDao;
import com.probiz.estore.system.model.AppAdminSearchCriteria;


/**
 * AppAdmin Business Delegate (Proxy) implementation to handle communication between web and
 * persistence layer. Implementation of AppAdminManager interface.
 * Developer introduced interfaces should be declared here. Won't get overwritten.
 */
public class AppAdminManagerImpl extends AppUserManagerImpl<AppAdmin> implements com.probiz.estore.system.service.AppAdminManager {

	private AppAdminDao appAdminDao = null;
	
	
	public void setAppAdminDao(AppAdminDao appAdminDao) {
		this.appAdminDao = appAdminDao;
	}

	@Override
	protected void initManager() {
		this.dao = appAdminDao;
		this.appUserDao = appAdminDao;
	}

	@Override
	protected void preDelete(AppAdmin entity) {
		
	}

	@Override
	protected void preSave(AppAdmin entity) {
		
	}

	public int getProvidersCount(Integer providerId) {
		return 0;
	}

	public List<AppAdmin> searchByCriteria(AppAdminSearchCriteria appAdminSearchCriteria, SearchCriteria searchCriteria) {
		return appAdminDao.searchByCriteria(appAdminSearchCriteria, searchCriteria);
	}
	
	public void deleteFully(AppAdmin appAdmin){
		//在原账号和邮箱后增加后缀
		String suffix = "-Del"+DateUtil.fmtTodayToSix()+RandomStringUtils.random(6,false,true);
		appAdmin.setUsername(appAdmin.getUsername()+suffix);
		appAdmin.setEmail(appAdmin.getEmail()+suffix);
		this.save(appAdmin);
		this.flush();//必须flush，否则上面的save会被撤销。
		this.delete(appAdmin);
	}

	
}
